package bTree.LeetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 用最少数量的箭引爆气球 {
    public int findMinArrowShots(int[][] points) {
        List<int []>res=new ArrayList<>();
        int len=points.length;
        Arrays.sort(points,((o1, o2) -> Integer.compare(o1[0],o2[0])));
        int begin=points[0][0],end=points[0][1];
        for(int i=0;i<len;i++){
            if (points[i][0]>end){
                res.add(new int[]{begin,end});
                begin=points[i][0];
                end=points[i][1];
            } else if (points[i][0]<=end&&points[i][1]>=end) {
                begin=points[i][0];
            } else if (points[i][0]<=end&&points[i][1]<=end) {
                begin=points[i][0];
                end=points[i][1];
            }
        }
        res.add(new int[]{begin,end});
        return res.size();
    }
}